package com.example.lin.zyfypt_327ljd.model;

import com.example.lin.zyfypt_327ljd.bean.LoginBean;
import com.example.lin.zyfypt_327ljd.iface.RegisterListener;
import com.example.lin.zyfypt_327ljd.iface.Registeriface;
import com.example.lin.zyfypt_327ljd.service.RegisterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lin on 2017/4/20.
 */

//model 获取文章数据
public class RegisterModel implements Registeriface {
    private Retrofit retrofit;
    private  String BASEURL
            ="http://amicool.neusoft.edu.cn/";
    //构造函数
    public RegisterModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void getResult(String username, String password,String tel,final RegisterListener registerListener) {
        RegisterService registerService=retrofit.create(RegisterService.class);
        Call<LoginBean> call=registerService.reg(username,password,tel);
        call.enqueue(new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                if (response.isSuccessful() && response != null) {
                    registerListener.onResponse(response.body());
                }
                else registerListener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                registerListener.onFail(t.toString());
            }
        });
    }
}
